﻿package net.wangit.view.unit.grid;

import net.wangit.Row;
import net.wangit.context.ActionContext;
import net.wangit.view.unit.UnitComponent;
import net.wangit.view.util.Html;

public class HorizontalGroup extends FormGrid {

	public HorizontalGroup(ActionContext ac, UnitComponent unit) {
		super(ac, unit);
	}

	protected void writeRow(ActionContext ac, StringBuffer html, Row row,
			int rowIndex, String rowCss) {
		html.append("<table id=\"").append("u_g_").append(uc.getId()).append(
				"\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">");
		setHead(html);
		html.append("<tr>");
		if (top.size() > 0) {
			html
					.append("<td class=\"")
					.append("GHW")
					.append(
							"\"><table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td class=\"")
					.append("GHC").append("\">");
			beginTable(html);
			top.write(ac, html, row, rowIndex, rowCss);
			html.append("</table>");
			html.append("</td></tr></table></td>");
		}
		for (int i = 0; i < groups.size(); i++) {
			Group group = (Group) groups.get(i);
			html
					.append("<td class=\"")
					.append("GHW")
					.append(
							"\"><table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td class=\"")
					.append("GHC").append("\">");
			beginTable(html);
			group.write(ac, html, row, rowIndex, rowCss);
			html.append("</table>");
			html.append("</td></tr></table></td>");
		}

		html.append("</tr></table>");
	}

	protected void beginTable(StringBuffer html) {
		html.append("<table cellpadding=\"0\" width=\"100%\"");
		if (uc.isShowCellBorder())
			html.append(" cellspacing=1 class=\"").append("DB").append("\"");
		else
			html.append(" cellspacing=\"0\"");
		html.append(">");
		setColsGroup(html);
	}

	protected void setHead(StringBuffer html) {
		html.append("<tr>");
		if (top.size() > 0)
			html.append("<td class=\"").append("GHT").append("\"></td>");
		for (int i = 0; i < groups.size(); i++) {
			Group group = (Group) groups.get(i);
			html.append("<td");
			Html.setAttribute(html, group.getGroupAttribute());
			html.append(" class=\"").append("GHT").append("\">").append(
					group.getGroupName()).append("</td>");
		}

		html.append("</tr>");
	}
}
